<template>
  <div class="page" style="position:relative;">
    <div class="layui-fluid">
      <div class="pagetop">
        <Search :seadate="searchArr"></Search>
      </div>
      <div class="layui-card-body">
        <Tables
          :fdate="pdate"
          :result="res"
          height="430"
          :totalCount="totalRows"
          :pageNumber="curindex"
          :fbtn="btn"
        ></Tables>
      </div>
      <div class="xuanfu" v-show="isshow == 1" style="display:none;">
        <div class="layui-card-body">
          <div class="layui-form" lay-filter>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label" style="font-weight:bold;font-size:15px;">商品设置</label>
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label"></label>
              <div class="layui-input-inline">
                <div class="layui-upload">
                  <div class="layui-upload-list">
                    <!-- <img class="layui-upload-img" :src="itemData.imageUrl?itemData.imageUrl:'http://kedoujfpc.tongdui365.com/static/common/image/zwyl.jpg'" width="100" height="100" style="border:1px solid #eee;">-->
                    <img
                      class="layui-upload-img"
                      :src="
                        itemData.logoUrl
                          ? itemData.logoUrl
                          : 'http://kedoujfpc.tongdui365.com/static/common/image/zwyl.jpg'
                      "
                      width="100"
                      height="100"
                      style="border:1px solid #eee;"
                    />
                  </div>
                </div>
              </div>
            </div>


            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-inline">
                  <input
                    type="text"
                    name
                    disabled="disabled"
                    v-model="itemData.name"
                    placeholder
                    autocomplete="off"
                    class="layui-input"
                    maxlength="11"
                  />
                </div>
              </div>
            </div>

             <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">PV分润总值</label>
                <div class="layui-input-inline">
                  <input
                    type="text"
                    name
                    v-model="amountlimit"
                    placeholder
                    autocomplete="off"
                    class="layui-input"
                  />
                </div>
                <div class="layui-form-mid">%</div>
                <div class="layui-form-mid layui-word-aux">PV分润比例,如10表示10%</div>
              </div>
            </div>

          

         

            <div class="layui-form-item">
              <div class="layui-input-block" style="top:10px;left:100px;">
                <button class="layui-btn" @click="save()" lay-submit lay-filter="formDemo">立即提交</button>
                <button
                  class="layui-btn layui-btn-primary"
                  @click="quxiao()"
                  lay-submit
                  lay-filter="formDemo"
                >取消</button>
              </div>
            </div>
            <!--// -->
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Tables from "../common/tables.vue";
import Search from "../common/search.vue";
export default {
  name: "ucshoppvadd",
  components: { Tables, Search },
  data() {
    return {
      pdate: [], //表头
      res: "", //内容
      totalRows: "", //总数量
      curindex: 1, //页数
      btn: [], //按钮
      searchArr: [], //搜索
      isShow: false,
      seapram: "",
      isshow: 0,

      amountlimit:"",
      mallType: "2",
      itemData: {
        name: "",
        shopId: "",
      }, //商品回选
    };
  },
  mounted() {
    this.getdate();
    this.getsearch();
  },
  methods: {
    getdate: function () {
      var _this = this;
      var url = "/mallbean/bapi/v1.9/item";
      if (_this.seapram) {
        var dates = {
          size: pageSize,
          page: _this.curindex,
          //sort:'createAt,DESC',
          //  "settingType.in": "COMMODITY"
        };
        var res = _this.seapram;
        for (var i = 0; i < res.length; i++) {
          dates[res[i].key] = res[i].val;
        }
      } else {
        var dates = {
          size: pageSize,
          page: _this.curindex,
          //sort:'createAt,DESC',
          // "settingType.in": "COMMODITY"
        };
      }
      //alert(url+"//"+JSON.stringify(dates))
      ajaxRequest(url, "GET", "json", dates, function (ret, err) {
        //alert(url+"//"+JSON.stringify(ret))
        var arr = [];
        arr[0] = [
          { field: "id", title: "商品ID" },
          { field: "name", title: "商品名称" },
          {
            field: "logoUrl",
            title: "商品图片",
            templet:
              '<div><img src="{{d.logoUrl}}" style="display: inline-block; height: 100%;"></div>',
          },
          {
            field: "price",
            title: "原市场价(元)",
            templet: function (d) {
              return d.price.marketPrice / 100;
            },
          },
          {
            field: "price",
            title: "现优惠价(元)",
            templet: function (d) {
              return d.price.specialPrice / 100;
            },
          },
          {
            field: "activeStatus",
            title: "状态",
            templet: function (d) {
              if (d.activeStatus == "ENABLE") {
                return "在售";
              } else if (d.activeStatus == "DISABLE") {
                return "下架";
              } else return "删除";
            },
          },
          {
            field: "itemSkuList",
            title: "销量",
            templet: function (d) {
              return d.saleStock.saleAmount;
            },
          },
          {
            field: "itemSkuList",
            title: "库存",
            templet: function (d) {
              return d.saleStock.stockAmount;
            },
          },
          {
            field: "right",
            title: "操作",
            width: "120",
            fixed: "right",
            templet: function (d) {
              var str =
                '<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="detail">选取</a>';
              return str;
            },
          },
        ];
        _this.pdate = arr;
        _this.res = ret.data.list; //res1;
        _this.totalRows = ret.data.totalRows;
        _this.curindex = ret.data.page + 1;
      });
    },
    getsearch: function () {
      var arr = [{ field: "name", title: "商品名称", type: "input" }];
      this.searchArr = arr;
    },
    page: function (index, obj) {
      //alert(JSON,stringify(obj))
      this.curindex = index;
      this.getdate();
    },
    sousuo: function (pram) {
      //alert(JSON.stringify(pram))
      this.seapram = pram;
      this.res = "";
      this.totalRows = "";
      this.curindex = 1;
      this.getdate();
    },
    addData: function () {
      // this.$router.push({name:'khadd'})
    },
    detailInfo: function (data) {
      var _this = this;
      var id = data.id;
      _this.isshow = 1;
      var url = "/mallbean/papi/v1.9/item/" + id; //回选商品
      //var url="/retail/bapi/v1.9/share-bonus/"+_this.id  //回选设置信息
      ajaxRequest(url, "GET", "json", "", function (ret, err) {
        _this.itemData = ret.data;
        _this.itemData.shopId = ret.data.id;
      });
    },
    quxiao: function () {
      var _this = this;
      //_this.itemData={};
      _this.isshow = 0;
    },
    save: function () {
      var _this = this;
      var url = "/profit/bapi/v1.9/platformp-rofit";
      var dates = {
        commodityId: _this.itemData.shopId,
        mallType: _this.mallType,
        amountlimit : Number(_this.amountlimit),
        settingType: "COMMODITY",
      };
      // alert(JSON.stringify(dates))
      ajaxRequest(url, "POST", "json", dates, function (ret, err) {
        layer.msg("设置成功");
        _this.isshow = 0;
        setTimeout(function () {
          var index = parent.layer.getFrameIndex(window.name);
          //alert(JSON.stringify(datas)+"//"+window.name)
          parent.layer.close(index);
          parent.location.reload();
        }, 1000);
      });
    },
    screens: function () {
      return screen();
    },
  },
  updated: function () {
    this.isShow = true;
    var _this = this;
    layui.use("form", function () {
      var form = layui.form;
      form.render();
    });
  },
};
</script>
<style scoped>
/**/
.xuanfu {
  background-color: #ffffff;
  width: 80%;
  font-size: 15px;
  position: absolute;
  left: 10%;
  top: 20px;
  z-index: 1;
}
</style>